﻿/*
Author: Aaron
Date: 2015-05-30
Description: 首页动态加载数据
*/
var tpl1 = [
              ' <div class="task-list-panel">',
              ' <div class="group-list">',
              '{@each data as it, k}',
              '<div class="group-item">',
              //'<div class="group-header"> <span class="ng-binding">已过期</span> <span class="badge ml_20 ng-binding">1</span> </div>',
              ' <div class="group-task-item slide-trigger f-clear">',
              '<div class="task-main" taskid="${it.KeyId}"> <span class="task-title ng-binding">${it.TaskDesc}</span> </div>',
             // '<div class="task-badges"><span class="task-badge icon icon-time badge-expire-due" title="任务已经截止">02-10</span> <span class="task-badge icon icon-desktop icon-project-name" title="熟悉 Worktile">熟悉 Worktile</span> </div>',
              //'<div class="task-members"><a class="mr_5 avatar avatar-30" member="member" size="30" title="梅郑冬" href="javascript:;"> <span class="avatar-face"><span class="avatar-text">梅</span></span> </a></div>',
              '</div>',
             '</div>',
              '{@/each}',
              '</div>',
              '</div>'
].join('\n');

$(function () {
    $(".worktab li").click(function () {

        if ($(this).find("a").hasClass('cur')) {
            return;
        }

        $(".worktab li").find("a").removeClass("cur");
        $(this).find("a").addClass("cur");
        var ind = $(".worktab li").index($(this));
        $(".worktabcon").addClass("f-hide");
        $(".tasktab li").parents(".g-main").find(".worktabcon").eq(ind).removeClass("f-hide");

        change_top_tab($(this).find("a").attr('ID'));
    });

    $(".tasktab li").click(function () {
        $(".tasktab li").find("a").removeClass("cur");
        $(this).find("a").addClass("cur");
        var ind = $(".tasktab li").index($(this));
        $(".mytask").addClass("f-hide");
        $(".tasktab li").parents(".mytasklist").find(".mytask").eq(ind).removeClass("f-hide");
        change_top_tab($('.tasktab li').eq(ind).attr('model'));
    });


    $(".tasktab2 li").click(function () {
        var ind = $(".tasktab2 li").index($(this));
        if ($('.tasktab li').eq(ind).find(".cur").length > 0) {
            return;
        }
        $(".mytask").addClass("f-hide");
        $(".tasktab2 li").parents().find(".mytask").eq(ind).removeClass("f-hide");
        $(".tasktab li").find("a").removeClass("cur");
        $(".tasktab2 li").parents().find(".tasktab li").eq(ind).find("a").addClass("cur");
        change_top_tab($('.tasktab li').eq(ind).attr('model'));
    });

    change_top_tab('unreceived');

    $('.task-main').live('click', function () {
        $(".slide-content").show();
        taskid = $(this).attr('taskid');
        $.ajax({
            type: 'post',
            url: '/task/gettask/' + taskid,
            cache: false,
            dataType: 'json',
            success: function (d) {
                showInfo(d, function (d) {
                    var task = d.data;
                    $('#spTitle').text(task.TaskTitle);
                    $('#spKind').text(tasklistkind[task.TaskListKind]);
                    $('#divDesc').text(task.TaskDesc);
                    if (task.TaskDesc.length > 0) {
                        $('#aTips').text('');
                    }
                    $('#txtTaskTitle').val(task.TaskTitle);
                    $('#txtTaskDesc').val(task.TaskDesc);
                    var str = juicer(tplComments, d.data);
                    $('.comments').html(str);
                    $('.comment-list').find('.part-loading').hide();

                    var userStr = juicer(tplUser, d.data);

                    $('.entity-members').find('.removememberbtn').remove();

                    $(userStr).insertBefore($('.entity-members').find('.assignmenttaskbtn'));
                });
            }
        });

    });


});

/*
Ajax 获取 最新动态列表、我的任务列表
*/
function change_top_tab(key) {
    switch (key) {
        case 'my_feed':

            break;
        case 'my_task':
            change_top_tab('uncompleted');
            break;
        case 'uncompleted':

            $('#taskload').css({ display: "block" });
            ajaxPost('/App/GetUncompleted', function (d) {
                $('#taskload').css({ display: "none" });
                var str = juicer(tpl1, d);
                $("#uncompleted").html(str);
            });
            break;
        case 'completed':
            $('#taskload').css({ display: "block" });
            ajaxPost('/App/GetCompleted', function (d) {
                $('#taskload').css({ display: "none" });
                var str = juicer(tpl1, d);
                $("#completed").html(str);
            });
            break;
        case 'expired':

            $('#taskload').css({ display: "block" });
            ajaxPost('/App/GetExpired', function (d) {
                $('#taskload').css({ display: "none" });
                var str = juicer(tpl1, d);
                $("#expired").html(str);
            });
            break;
        case 'unreceived':
            $('#taskload').css({ display: "block" });
            ajaxPost('/App/GetUnReceived', function (d) {
                $('#taskload').css({ display: "none" });
                var str = juicer(tpl1, d);
                $("#unreceived").html(str);
            });
            break;
        default:
    }
}

